/*
 * PageContact.java
 *
 * Created on 6 de marzo de 2007, 21:14
 *
 * Copyright(c) 2007 Duam Sistemas.
 * All Rights Reserved.
 * This software is the proprietary information of Duam Sistemas.
 */
package ar.org.fiel.tarifasocial.ui.pages.pub;

import ar.org.fiel.tarifasocial.om.model.User;
import ar.org.fiel.tarifasocial.om.peer.UserPeer;
import ar.org.fiel.tarifasocial.ui.components.CustomListView;
import ar.org.fiel.tarifasocial.ui.components.MetaConstants;
import ar.org.fiel.tarifasocial.ui.components.TypeConstants;
import ar.org.fiel.tarifasocial.ui.pages.PagePublic;
import java.util.List;
import org.apache.log4j.Logger;
import wicket.markup.html.pages.RedirectPage;

/**
 * @author Duam Sistemas (http://www.duamsistemas.com.ar)
 */
public class PageContact extends PagePublic
{
    private static Logger logger = Logger.getLogger(PageContact.class);
    
    protected void init()
    {
        try
        {
            List<User> users = UserPeer.retrieveAllContacts();
            
            String[][] meta = this.buildMeta();
            
            CustomListView listViewContacts = new CustomListView("listViewContacts", users, meta)
            {
                protected void onClick(Object object)
                {
                    User user = (User) object;
                    this.setResponsePage(new RedirectPage(user.getMailURL()));
                }
                public void updateList()
                {
                }
            };
            
            this.add(listViewContacts);
        }
        catch (Exception exception)
        {
            logger.error("ERROR", exception);
            this.error(exception.getMessage());
        }
    }
    
    private String[][] buildMeta()
    {
        String[][] meta = new String[5][MetaConstants.META_ARRAY_SIZE];
        
        meta[0][MetaConstants.TYPE] = TypeConstants.STRING;
        meta[0][MetaConstants.GETTER] = "getName";
        meta[0][MetaConstants.ID] = "labelName";
        
        meta[1][MetaConstants.TYPE] = TypeConstants.STRING;
        meta[1][MetaConstants.GETTER] = "getLastName";
        meta[1][MetaConstants.ID] = "labelLastName";
        
        meta[2][MetaConstants.TYPE] = TypeConstants.STRING;
        meta[2][MetaConstants.GETTER] = "getCompanyPosition";
        meta[2][MetaConstants.ID] = "labelPosition";
        
        meta[3][MetaConstants.TYPE] = TypeConstants.STRING;
        meta[3][MetaConstants.GETTER] = "getCompany";
        meta[3][MetaConstants.ID] = "labelCompany";
        
	meta[4][MetaConstants.GETTER] = "getEmail";
	meta[4][MetaConstants.ID] = "linkMail";
	meta[4][MetaConstants.TYPE] = TypeConstants.ACTION;
	meta[4][MetaConstants.LABEL_ID] = "labelMail";
	
        return meta;
    }
    
}